package com.example.springboot3.appConfiguration;

import com.example.springboot3.intercept.LoginIntercept;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class AppConfiguration implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginIntercept())
                .addPathPatterns("/**")
                .excludePathPatterns("/**/login.html")
                .excludePathPatterns("/**/reg.html")
                .excludePathPatterns("/**/*.js")
                .excludePathPatterns("/**/*.css")
                .excludePathPatterns("/**/*.jpg")
                .excludePathPatterns("/**/*.png")
                .excludePathPatterns("/**/user/getAll")
                .excludePathPatterns("/**/user/error")
                .excludePathPatterns("/**/user/transactional");
    }

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        //针对静态页面不生效
        configurer.addPathPrefix("api",c->true);
    }
}
